import type { FormItemRule } from 'element-plus'

import { domainRules } from './domain'

export const useRules = formState => {
  return computed<Record<string, FormItemRule[]>>(() => ({
    domains: [...domainRules],
    type: [{ required: true, message: '请选择记录类型', trigger: 'change' }],
    name: [
      {
        validator: hostValidate(() => formState.domains),
        trigger: 'blur'
      }
    ],
    priority: [
      ...(formState.type === 'MX'
        ? [{ required: true, message: '请输入MX优先级', trigger: 'blur' }]
        : [])
    ],
    value: [
      { required: true, message: '请输入记录值', trigger: 'blur' },
      {
        trigger: 'blur',
        // 服务器IP、CDN域名、邮件服务域名
        validator: logValueValidate(() => formState.type!)
      }
    ]
  }))
}
